package com.mes.basicdata.domain;
/**
 * @author SnowBear
 * @time 2017/3/15
 */
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

@Entity()
@Table(name = "R_EQUIPMENT_CLASS")
@BatchSize(size=10)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class DeviceClass extends BasicModel implements Serializable {
private static final long serialVersionUID = 1L;

	// 设备类唯一号
	@Id
	@GenericGenerator(name = "uuid", strategy = "assigned")
	@Column(name="UUID",scale=0)
	private String uuid;

	// 设备类编号
	@Column(name = "EQUIPMENT_CLASS_ID", length = 50)
	private String deviceClassId;
	
	// 设备类名称
	@Column(name = "EQUIPMENT_CLASS_NAME")
	private String deviceClassName;
	
	// 工种类型
	@Column(name = "WORK_TYPE")
	private String workType;
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="WORK_TYPE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'optype'", referencedColumnName="TYPESNAME"))
	})
	private TypesData workTypeDesc;
	
	// 是否有效
	@Column(name = "EFFECTIVE", precision = 2, scale = 0)
	private Boolean isEffective;
	
	// 资源关键等级
	@Column(name = "CRITICAL_LEVEL", precision = 2, scale = 0)
	private Integer criticalLevel;
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="CRITICAL_LEVEL",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'critical_level'", referencedColumnName="TYPESNAME"))
	})
	private TypesData criticalLevelDesc;
	
	// 父设备类
	@Column(name = "PARENT_UID")
	private String parentDeviceClassUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PARENT_UID",insertable=false,updatable=false)
	private DeviceClass parentDeviceClass;
	
	// 子设备类
	@Transient
	private Set<Device> childDeviceClasses = new HashSet<Device>(0);	
	
	// 子机床
	@Transient
	private Set<Device> devices = new HashSet<Device>(0);

	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.uuid;
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.uuid = uuid;
	}
	
	public DeviceClass getParentDeviceClass() {
		return parentDeviceClass;
	}

	public void setParentDeviceClass(DeviceClass parentDeviceClass) {
		this.parentDeviceClass = parentDeviceClass;
	}

	public String getParentDeviceClassUid() {
		return parentDeviceClassUid;
	}

	public void setParentDeviceClassUid(String parentDeviceClassUid) {
		this.parentDeviceClassUid = parentDeviceClassUid;
	}

	public Set<Device> getDevices() {
		return devices;
	}

	public void setDevices(Set<Device> devices) {
		this.devices = devices;
	}

	public Set<Device> getChildDeviceClasses() {
		return childDeviceClasses;
	}

	public void setChildDeviceClasses(Set<Device> childDeviceClasses) {
		this.childDeviceClasses = childDeviceClasses;
	}
	
	/*public String getDeviceClassUid() {
		return this.deviceClassUid;
	}
	
	public void setDeviceClassUid(String deviceClassUid) {
		this.deviceClassUid = deviceClassUid;
	}
	*/
	
	public String getDeviceClassId() {
		return this.deviceClassId;
	}
	
	public void setDeviceClassId(String deviceClassId) {
		this.deviceClassId = deviceClassId;
	}
	
	public String getDeviceClassName() {
		return this.deviceClassName;
	}
	
	public void setDeviceClassName(String deviceClassName) {
		this.deviceClassName = deviceClassName;
	}

	/*public String getCreatorUid() {
		return this.creatorUid;
	}
	
	public void setCreatorUid(String creatorUid) {
		this.creatorUid = creatorUid;
	}*/
	
	/*@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)//原来是cascade=none,insertable = false, updateable = false
	@JoinColumn(name = "CREATOR", nullable = false,insertable=false,updatable=false)
	public Employee getCreator() {
		return this.creator;
	}
	
	public void setCreator(Employee creator) {
		this.creator = creator;
	}*/
	
	/*@Column(name = "CREATE_TIME", length = 7)
	public Date getCreateTime() {
		return this.createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}*/

	public String getWorkType() {
		return this.workType;
	}
	
	public void setWorkType(String workType) {
		this.workType = workType;
	}
	
	/*@Column(name = "NOTES")
	public String getNotes() {
		return this.notes;
	}
	
	public void setNotes(String notes) {
		this.notes = notes;
	}*/

	public Integer getCriticalLevel() {
		return this.criticalLevel;
	}
	
	public Boolean getIsEffective() {
		return isEffective;
	}

	public void setIsEffective(Boolean isEffective) {
		this.isEffective = isEffective;
	}

	public void setCriticalLevel(Integer criticalLevel) {
		this.criticalLevel = criticalLevel;
	}
	

}
